package com.proyecto.track.dao;

import java.util.List;

import org.hibernate.SessionFactory;

import com.proyecto.track.bo.Coment;


public class CommentDAOImp implements CommentDAO{

	private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	@Override
	public Long createComment(Coment coment) {
		sessionFactory.getCurrentSession().save(coment);
		return coment.getId();
	}

	@Override
	public Long deleteComment(Coment coment) {
		Long id = coment.getId();
		sessionFactory.getCurrentSession().delete(coment);
		return id;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Coment> searchComment() {
		return  sessionFactory.getCurrentSession().createQuery("from Coment").list();
	}

	@Override
	public Coment searchComment(Long id) {
		return (Coment) sessionFactory.getCurrentSession().get(Coment.class, id);
	}

}
